package com.maomao.holding;

import java.time.Clock;
import java.util.*;

/**
 *
 * @author admin
 * @date 2018/3/28
 */
public class HashMapSort {
    public static HashMap<Integer,User> sortHashMap(HashMap<Integer,User> map){
        Set<Map.Entry<Integer,User>> entrySet=map.entrySet();
        List<Map.Entry<Integer,User>> list=new ArrayList<Map.Entry<Integer, User>>(entrySet);
        Collections.sort(list, new Comparator<Map.Entry<Integer, User>>() {
            @Override
            public int compare(Map.Entry<Integer, User> o1, Map.Entry<Integer, User> o2) {
                return o1.getValue().getAge()-o2.getValue().getAge();
            }
        });
        LinkedHashMap<Integer,User> linkedHashMap=new LinkedHashMap<Integer,User>();
        for (Map.Entry<Integer,User> entry:list){
            linkedHashMap.put(entry.getKey(),entry.getValue());
        }
        return linkedHashMap;
    }

}
